<?php require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
require_once($_SERVER['DOCUMENT_ROOT']."/Modules/MGK20XF5/moduleconf.php");
MYDCONN();


	if (!isset($_GET['Time'])) { $_GET['Time'] = date("Y-m-01"); }
	if (isset($_GET['DCTP'])) {
		$PR_Qur = " AND TYPE = {$_GET['DCTP']}";
	} else {
		$PR_Qur = " AND Time >= '{$_GET['Time']} 00:00:00'";
	}

echo '<div class="title">Documentos</div>';
form_pr('doccenter_show','','','post');
	echo '<table width="98%"  border="0" cellpadding="3" cellspacing="1">';

  if (!isset($_GET['Iv'])) { 
  
  echo '<tr bgcolor="#F2F2F2">
  	<td width="3%">N.</td>
  	<td width="5%">Tipo</td>
    <td width="25%">Título</td>
    <td width="8%">Data</td>
    <td width="10%">Autor</td>
    <td width="6%">Responsavel</td>
  </tr>';

    $GET = $GLOBALS['MYD']->db_array("SELECT 
					a.Ref,
					a.Title,
					a.Body,
					a.Time,
					a.Author,
					a.DocRefer,
					sug_Name AS Attrib,
					hcdc_types.NAME AS TYPE
				FROM doccenter_document AS a
				INNER JOIN hcdc_types ON hcdc_types.REF = a.TYPE
				INNER JOIN sys_usergroups ON sug_ID = a.Attrib
				WHERE STATUS = 1
				{$PR_Qur}"); 
	for ($f = 1; $f <= $GET[0]; $f++) { 
	
		echo'<tr onclick="replaceUrl(\'app\',\'Modules/MGK20XF5/mdocs.php?Iv='.$GET[$f]['Ref'].'\');" ';
		if (isset($GET[$f]['USER'])) { echo 'bgcolor="#00CC33"'; } else { echo 'bgcolor="#D3D6E4"'; } echo '>
		<td>'.$GET[$f]['DocRefer'].'</td>
		<td>'.$GET[$f]['TYPE'].'</td>
		<td>'.$GET[$f]['Title'].'</td>
		<td>'.$GET[$f]['Time'].'</td>
		<td>'.$GET[$f]['Author'].'</td>
		<td>'.$GET[$f]['Attrib'].'</td>
		</tr>';
   }  
   } else {
	echo '<tr bgcolor="#D3D6E4">
		<td colspan="5">^ Listagem de Documentos Minimizada | <a onclick="replaceUrl(\'app\',\'Modules/MGK20XF5/mdocs.php?jB=4\');">Maximizar (+)</a></td>
		</tr>
		</table>'; 
echo '<div style="float:left;width:50%"><table width="100%"  border="0" cellspacing="1" cellpadding="3">';

    $CResults = "SELECT 
					a.Ref,
					a.Title,
					a.Body,
					a.Time,
					YEAR(a.Time) AS Y,
					a.Author,
					a.DocRefer,
					sug_Name AS Attrib,
					hcdc_types.NAME AS TYPE
				FROM doccenter_document AS a
				INNER JOIN hcdc_types ON hcdc_types.REF = a.TYPE
				INNER JOIN sys_usergroups ON sug_ID = a.Attrib
				WHERE a.Ref = {$_GET['Iv']}";
	$GET = $GLOBALS['MYD']->db_array($CResults); 
	for ($f = 1; $f <= $GET[0]; $f++) { 
	mn_field('hidden','ED','DOC',$GET[$f]['Ref'],'','','False','');

          echo '<tr bgcolor="'.gridlines($f).'">
            <td colspan="2">Propriedades do Documento ';
	mn_field('button','ED','ed_Doc','Editar documento','','','False','" onclick="
		document.doccenter_show.action=\''.$MODURL.'bdocs.php?DOCX='.$GET[$f]['Ref'].'\';
		subform(\'doccenter_show\',\'app\');');
	echo '</td>
          </tr>
          <tr bgcolor="#F2F2F2">
            <td colspan="2">'.$GET[$f]['TYPE'].': '.$GET[$f]['DocRefer'].'/'.$GET[$f]['Y'].'</td>
          </tr>
          <tr bgcolor="#F2F2F2">
            <td width="21%">Título:</td>
            <td>'.$GET[$f]['Title'].'</td>
          </tr>
          <tr bgcolor="#F2F2F2">
            <td width="21%">Anexos:</td>
            <td><table width="100%"  border="0" cellspacing="1" cellpadding="1">
          <tr>
            <td bgcolor="#DFE4D6">Ficheiros</td>
          </tr>';

    $Files = $GLOBALS['MYD']->db_array("SELECT FILE FROM doccenter_files WHERE DOC = {$GET[$f]['Ref']}"); 
	for ($g = 1; $g<= $Files[0]; $g++) { 
       echo '<tr>
            <td bgcolor="#DFE4D6"><a href="'.$GLOBALS['URL'].'Shared/Grx/img.php?IMG='.$Files[$g]['FILE'].'">'.$Files[$g]['FILE'].'</a></td>
          </tr>';
	}
    echo '</table></td>
          </tr>
          <tr bgcolor="#F2F2F2">
            <td>Texto:</td>
            <td>'.nl2br($GET[$f]['Body']).'</td>

          </tr>
          <tr bgcolor="#F2F2F2">
            <td>Responsável: </td>
            <td>'.$GET[$f]['Attrib'].'</td>
          </tr>
          <tr bgcolor="#FBFBFB">
            <td colspan="2">&nbsp;</td>
          </tr>
          <tr bgcolor="#F2F2F2">
            <td colspan="2">Assinado.</td>
          </tr>
          <tr bgcolor="#FBFBFB">
            <td colspan="2">'.nl2br($GET[$f]['Author']).'</td>
          </tr>
		 </table>
	</div>
	<div style="width:45%;float:right;background-color:#FBFBFB;padding:10px"> Leituras: ';
	$Res = $GLOBALS['MYD']->db_array("SELECT 
					smb_Name,
					TIMEREAD,
					Dcr_Note,
					main_offices.name
				FROM staff_members
				INNER JOIN main_users ON StaffMember = smb_ID
				INNER JOIN main_offices ON main_offices.ref = main_users.ref_office
				LEFT OUTER JOIN doccenter_userreads ON main_users.ref = USER AND DOC = {$GET[$f]['Ref']}
				WHERE smb_Flag = 2
				GROUP BY smb_ID
				ORDER BY name, smb_Name"); 
		for ($g = 1; $g <= $Res[0]; $g++) {
			if(isset($Res[$g]['TIMEREAD'])){$bg=gridlines($g);}else{$bg='#FFC0C0';}
			echo '<div style="background-color:'.$bg.';margin:1px;padding:3px"><div style="width:200px;float:left">'.$Res[$g]['name'].'</div>'.$Res[$g]['TIMEREAD'].' '.$Res[$g]['smb_Name'].': '.$Res[$g]['Dcr_Note'].'</div>';}
	}
	echo '</div>';
	}?>
</form>